<template>
  <!-- <div>消息管理</div> -->
  <div style="width: 98%;margin: 0 auto;background-color: white;margin-top: 10px; padding-bottom: 20px;">
    <div style="height: 20px;"></div>
    <div style="width: 98%; margin: 0 auto;">
      <div>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item label="消息标题：">
            <el-input v-model="formInline.esReceiver" placeholder="请输入消息标题"></el-input>
          </el-form-item>
          <el-form-item label="发送内容:">
            <el-input v-model="formInline.esContent" placeholder="请输入发送内容"></el-input>
          </el-form-item>
          <el-form-item label="接收人:">
            <el-input v-model="formInline.esTitle" placeholder="请输入接收人"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="chaxun()">查询</el-button>
            <el-button type="primary" @click="onSubmit">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="biaonei">
        <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%" id="exxx"
          :cell-style="{ textAlign: 'center' }" border stripe
          :header-cell-style="{ fontSize: '14px', color: '#000000', backgroundColor: '#eef1f6' }"
          @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center">
          </el-table-column>
          <el-table-column label="#" width="70" align="center">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="esTitle" label="消息标题" width="150" align="center">
          </el-table-column>
          <el-table-column label="发送内容">
            <template slot-scope="scope">
              <div :style="{ 'overflow': 'hidden', 'text-overflow': 'ellipsis', 'white-space': 'nowrap' }">
                {{ scope.row.esContent }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="esReceiver" label="接收人" width="200" align="center">
          </el-table-column>
          <el-table-column prop="esSendNum" label="发送次数" align="center">
          </el-table-column>
          <el-table-column label="发送状态" width="120" align="center">
            <template slot-scope="scope">
              {{ zhuantai(scope.row.esSendStatus) }}
            </template>
          </el-table-column>
          <el-table-column prop="updateTime" label="发送时间" width="180" align="center">
          </el-table-column>
          <el-table-column prop="esType_dictText" label="发送方式" align="center">
          </el-table-column>
          <el-table-column label="操作" align="center" width="120">
            <template slot-scope="scope">
              <el-button class="xiaoan" type="primary" plain @click="xiangq(scope.row)">详情</el-button>
              <!-- <el-button class="xiaoan" type="danger" plain @click="open(scope.row.id)">删除</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <div class="block ">
          <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page.sync="currentPage2" :page-sizes="[5, 10, 20, 50]" :page-size="10"
            layout="total,sizes, prev, pager, next" :total="yenum">
          </el-pagination>
        </div>

      </div>

      <!-- 弹框 -->
      <el-drawer title="详情" :visible.sync="drawers" :before-close="handleClose">
        <div>
          <el-form size="mini" :model="ruleForm" ref="ruleForm" label-width="120px" class="demo-ruleForm">
            <el-form-item label="消息标题:" prop="esTitle">
              <el-input v-model="ruleForm.esTitle" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="发送内容:">
              <el-input v-model="ruleForm.esContent" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="发送所需参数-:">
              <el-input v-model="ruleForm.phone" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="接收人:">
              <el-input v-model="ruleForm.esReceiver" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="发送方式:">
              <el-input v-model="ruleForm.esType_dictText" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="发送时间:">
              <el-input v-model="ruleForm.updateTime" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="发送状态:">
              <el-input v-model="ruleForm.esSendStatus_dictText" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="发送次数:">
              <el-input v-model="ruleForm.esSendNum" style="width: 100px;" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="发送失败原因:">
              <el-input v-model="ruleForm.remark" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="备注:">
              <el-input v-model="ruleForm.esParam" :disabled="true"></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div style="float: right; margin-right: 50px; margin-top: 20px;">
          <el-button @click="drawers = false">取消</el-button>
        </div>
      </el-drawer>
    </div>
  </div>
</template>

<script>
import { Gitlist } from '@/api/message'
export default {
  data() {
    return {
      tableData: [],
      formInline: {
        esReceiver: '',
        esContent: '',
        esTitle: ''
      },
      form: {
        pageSize: 10,
        pageNo: 1
      },
      yenum: 0, // 总条数
      currentPage2: 1,
      drawers: false,
      ruleForm: {},
    }
  },
  created() {
    this.chaxun()
  },
  methods: {
    onSubmit() {
      console.log('submit!');
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(this.multipleSelection)
    },
    handleSizeChange(val) {
      this.form.pageNum = val
      console.log(`每页 ${val} 条`)
      this.tai == 1 ? this.danyuan() : this.chaxun()
    },
    handleCurrentChange(val) {
      this.form.currPage = val - 1
      console.log(`当前页: ${val}`)
      this.tai == 1 ? this.danyuan() : this.chaxun()
    },
    async chaxun() {
      let res = await Gitlist(Math.floor(Date.now() / 1000), this.formInline, this.form)
      console.log(res)
      this.tableData = res.result.records
    },
    zhuantai(zhuang) {
      if (zhuang == 1) {
        return '发送成功'
      } else if (zhuang == 2) {
        return '发送失败'
      } else {
        return ''
      }

    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => { });
    },
    xiangq(nei) {
      this.drawers = true
      this.ruleForm = nei
      console.log(this.ruleForm)
    },
  }
}
</script>

<style lang="less" scoped>
.block {
  text-align: right;
  margin-top: 20px;
}

.el-drawer {
  width: 600px;

  .el-input {
    width: 250px;
  }
}
.xiaoan{
  padding: 5px 10px;
}
</style>
